package com.maxmlr.music.admin.controller;

import com.maxmlr.music.admin.entity.Dept;
import com.maxmlr.music.admin.param.TreeParam;
import com.maxmlr.music.admin.service.DeptService;
import com.maxmlr.music.common.base.BaseController;
import com.maxmlr.music.common.bean.ResultBean;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/**
 * @author max
 * @version 1.0
 * @ClassName DeptController
 * @Description 部门管理 控制器
 * @Copyright Copyright (c) 2020: www.maxmlr.com.
 * @since 2020-06-14
 */
@Slf4j
@RestController
@Api(value = "/admin/dept", tags = "Dept 控制器")
@RequestMapping("/admin/dept")
public class DeptController extends BaseController<DeptService, Dept> {

    @Autowired
    public DeptService service;

    /**
     * 保存
     *
     * @param dict
     * @return ResultBean<Boolean>
     */
    @PostMapping
    @RequiresPermissions("admin:dept:add" )
    public ResultBean<Boolean> save(Dept dept) {
        return ResultBean.ok(service.save(dept));
    }

    /**
     * 修改
     *
     * @param dict
     * @return ResultBean<Boolean>
     */
    @PutMapping
    @RequiresPermissions("admin:dept:edit" )
    public ResultBean<Boolean> update(Dept dept) {
        return ResultBean.ok(service.updateById(dept));
    }

    /**
     * 删除
     *
     * @param id
     * @return ResultBean<Boolean>
     */
    @DeleteMapping("/remove/{id}" )
    @RequiresPermissions("admin:dept:remove" )
    public ResultBean<Boolean> remove(@PathVariable("id" ) Serializable id) {
        return ResultBean.ok(service.removeById(id));
    }

    @GetMapping("/tree")
    public ResultBean<TreeParam<Dept>> tree() {
        return ResultBean.ok(service.getTreeParam());
    }

}
